<template>
  <div class="header">
    <h1>todos</h1>
    <input class="new-todo" placeholder="What needs to be done?" autofocus @keyup.enter="addTodo" v-model="name">
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { bus } from './main.vue'

@Component
export default class Header extends Vue {
  name = ''

  addTodo () {
    const name: string = this.name
    if (!name.trim()) return
    const date: Date = new Date()
    bus.$emit('addTodo', name, date)
    this.name = ''
  }
}
</script>
